package com.august.task;

import com.august.service.impl.CompanyVo;
import com.august.service.impl.HashVO;
import com.august.utils.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

public class MySqlTask implements Callable<List<HashVO>> {

    private int start;
    private int end;


    public MySqlTask(int start,int end){
        this.start = start;
        this.end = end;
    }

    @Override
    public List<HashVO> call() throws Exception {

        JdbcTemplate mysql1JdbcTemplate = SpringContextUtil.getBean("mysql1JdbcTemplate");

        String sql = "select * from student limit "+start+","+end;
        List<Map<String, Object>> mapList = mysql1JdbcTemplate.queryForList(sql);


        List<HashVO> hashVoList = mapList.stream().map(item -> {
            HashVO hashVO=new HashVO(String.valueOf(item.get("id")),Integer.toString(Objects.hashCode(item)));
            //HashVO hashVO = new HashVO();
           // hashMap.put(String.valueOf(item.get("id")),Integer.toString(Objects.hashCode(item)));
//            hashVO.setHashCode(Integer.toString(Objects.hashCode(item)));
//            hashVO.setReconKey(String.valueOf(item.get("id")));
            return hashVO;
        }).collect(Collectors.toList());

        return hashVoList;
    }
}
